package com.skywolf.chem.manager.controller;


import cn.hutool.core.lang.Assert;
import com.skywolf.chem.achievement.entity.CtSysAchievement;
import com.skywolf.chem.achievement.pojo.CtAchievementMatchPageParam;
import com.skywolf.chem.achievement.pojo.CtAchievementMatchParam;
import com.skywolf.chem.achievement.pojo.CtSysAchievementMatchDto;
import com.skywolf.chem.achievement.service.ICtSysAchievementService;
import com.skywolf.chem.common.config.data.DataSource;
import com.skywolf.chem.common.config.data.DataSourceNames;
import com.skywolf.chem.common.sysconfig.pojo.vo.PageVO;
import com.skywolf.chem.common.sysconfig.response.RespData;
import com.skywolf.chem.manager.entity.ActivityParam;
import com.skywolf.chem.manager.entity.ActivityVo;
import com.skywolf.chem.match.entity.Type;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 运动奖牌 控制器
 * </p>
 *
 * @author 
 * @since 2021-11-08
 */
@Slf4j
@RestController
@RequestMapping("/manager/achievement/all")
@Api(value = "运动奖牌", description = "赛事：运动奖牌")
public class CtSportAchievementController {

    @Autowired
    ICtSysAchievementService iCtSysAchievementService;

    @ApiOperation(value = "获取活动列表",notes = "获取活动列表")
    @RequestMapping(value = "/get/match/page",method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespData<CtSysAchievementMatchDto> getMatchList(@RequestBody @Validated CtAchievementMatchPageParam queryParam) {
        PageVO<CtSysAchievementMatchDto> page = iCtSysAchievementService.getMatchPageList(queryParam);
        return RespData.success(page);
    }


    @ApiOperation("创建赛事奖牌")
    @PostMapping("/match/create")
    public RespData<String> createCtSysAdvert(@Validated @RequestBody CtAchievementMatchParam param) throws Exception {
        CtSysAchievement model = new CtSysAchievement();
        Assert.isTrue(null != param.getMatchId(), "请选择关联赛事");
        BeanUtils.copyProperties(param,model);
        model.setMedalType(1);
        model.setDeleted(1);
        model.setOtherId(param.getMatchId());
        model.setCreatedTime(LocalDateTime.now());
        model.setUpdatedTime(LocalDateTime.now());
        model.setGmtCreate(LocalDateTime.now());
        model.setGmtModified(LocalDateTime.now());
        iCtSysAchievementService.addAchievement(model);
        return RespData.success();
    }

    @ApiOperation("更新赛事奖牌,上下架也通过这接口(传ID deleted)")
    @PostMapping("/match/update")
    public RespData<String> updateAdvert(@Validated @RequestBody CtAchievementMatchParam param) {
        Assert.isTrue(null != param.getId(), "更新时id不能为空");
        CtSysAchievement model = new CtSysAchievement();
        BeanUtils.copyProperties(param,model);
        model.setMedalType(1);
        model.setIsDeleted(param.getDeleted());
        if(param.getMatchId()!=null){
            model.setOtherId(param.getMatchId());
        }
        iCtSysAchievementService.updateAchievement(model);
        return RespData.success();
    }

}
